package cli;

import example.SocketServerUsage;
import picocli.CommandLine;

import java.util.concurrent.Callable;

@CommandLine.Command(name = "server", description = "启动数据库服务端")
public class ServerCommand implements Callable<Integer> {

    @CommandLine.Option(names = {"-c", "--config"}, required = true, description = "配置文件路径")
    private String configPath;

    @CommandLine.Option(names = {"--id"}, required = true, description = "节点ID")
    private String nodeId;

    @Override
    public Integer call() throws Exception {
        System.setProperty("node.id", nodeId);
        try {
            SocketServerUsage.main(new String[]{configPath});
        } catch (Exception e) {
            System.err.println("启动失败: " + e.getMessage());
            return 1;
        }
        return 0;
    }
}
